package com.yq.tcp;


import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/07/04 20:22
 * 服务器接收数据并进行判断，如果用户名和密码均是admin，
 * 则登录成功，否则登录失败，返回相应响应信息；
 * 客户端接收响应信息并输出登录结果。
 */
public class LoginClient {

    public static void main(String[] args) throws IOException {
        //创建socket
        Socket socket = new Socket("127.0.0.1", 8888);
        Scanner scanner = new Scanner(System.in);
        System.out.print("输入用户名：");
        String username = scanner.nextLine();
        System.out.print("输入用密码：");
        String password = scanner.nextLine();
        //    创建user对象
        User user = new User(username, password);
        //    获取
        OutputStream outputStream = socket.getOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(outputStream);
        //序列化发送
        out.writeObject(user);


        //返回接收的结果
        InputStream in = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int read = in.read(bytes);
        System.out.println("登录的结果为："+new String(bytes,0,read));



        socket.close();

    }
}
